<?php
//User interface that allows a user to select an incomplete inspection or start a new inspection.
	include 'commonAccountFunctions.php';
	
	session_start();
	$user = checkAuthentication();
	
	print_header();
?>	
	<div id="userDiv">
			<p id="userName">UserName: <?= $user ?></p>
			<form action="index.php">
				<button type="submit" class="unButtons">Log Out</button>
			</form>
			<form action="controlpanel.php">
				<button type="submit" class="unButtons">Back</button>
			</form>
		</div>
		<?php
			//reads in a specified directory that is in the file folder.
			function readFiles($folderName){
				$dir = "../files/" . $folderName;
				if (is_dir($dir)) {
					if ($dh = opendir($dir)) {
						$i = 0;
						while (($file = readdir($dh)) !== false) {
							if($file != "." and $file != ".."){
								$fileList[$i] = trim($file, ".txt");
								$i++;
							}
						}
						closedir($dh);
					}
				}
				return $fileList;
			}
			$inspectionList = readFiles("incompleteInspections");
			$protocolList = readFiles("templates");
			$facilityList = file("../files/facilityList.txt");
		?>
		<div id="incomplete">
			<p>Previous incomplete lab inspections:</p>
			<form action="viewCheckList.php" method="post">
				<select name="file">
					<?php
						foreach($inspectionList as $file){
					?>
								<option value="<?=$file?>"> <?=$file ?> </option>
					<?php 
						}
					?>
				</select>
				<button type="submit">Continue</button>
			</form>
		</div>
		<div id="newInspection">
			<p id="inspectionTitle">New Lab Inspection</p>
			<br />
			<form action="viewCheckList.php" enctype="multipart/form-data" method="post">
				<p>Facility:</p>
				<select name="facility">
					<?php foreach($facilityList as $facility){ ?>
							<option value="<?php echo trim($facility);?>_"><?php echo $facility;?></option>
						<?php } ?>
				</select>
				<br />
				<p>Checklist Protocol:</p>
				<select name="protocol">
				<?php
					foreach($protocolList as $protocol){
				?>
						 <option value="<?=$protocol?>"> <?=$protocol ?> </option>
				<?php 
					}
				?>
				</select>
				<br />
				<input type="submit" value="Create"/>
			</form>
		</div>

<?php
	print_footer();
?>